<template>
	<view class="container2">
		<cover-view class="laytab">
			<cover-view class="tab" :class="TabIndex==1?'select':''" @click="LayTab(1)">审批</cover-view>
			<cover-view class="tab left20" :class="TabIndex==2?'select':''" @click="LayTab(2)">电子文书</cover-view>
			<cover-view class="tab left20" :class="TabIndex==3?'select':''" @click="LayTab(3)">图片文书</cover-view>
		</cover-view>
		<template v-if="TabIndex==1">
			<view class="square1 top100">
				<view v-html="Expand.Context"></view>
			</view>
			<view class="square1">
				<view class="line2">
					<view class="name">承办人意见：</view>
					<view class="text indent">{{Entity.CBRYJ+(Entity.CBRYJ=="建议立案"?"":Entity.CBRYJ_Reason)}}</view>
				</view>
				<view class="line3">
					<view class="redbd"><view class="top">{{Item.ZBRRealName}}</view><view class="bottom">{{Item.ZBRLawNum}}</view></view>
					<view class="redbd"><view class="top">{{Item.XBRRealName}}</view><view class="bottom">{{Item.XBRLawNum}}</view></view>
					<view class="text right">{{Tools.ToDateStr(Entity.CBRYJ_Date)}}</view>
				</view>
				<view class="line2">
					<view class="name">承办机构审核意见：</view>
					<view class="text indent">{{Entity.CBJGSHYJ_IsAgree+(Entity.CBJGSHYJ_IsAgree=="拟同意"?"，建议该案件主办人是："+Item.ZBRRealName+"，协办人是："+Item.XBRRealNames+"。":"")}} </view>
				</view>
				<view class="line3" v-if="Entity.CBJGSHYJ_IsAgree!=''">
					<view class="redbd" v-if="Item.SignName_CBJG==''"><view class="top">{{Item.CBJGRealName}}</view><view class="bottom">{{Item.CBJGLawNum}}</view></view>
					<view class="signname" v-else><image :src="Item.SignName_CBJG" mode="heightFix" /></view>
					<view class="text right">{{Tools.ToDateStr(Entity.CBJGSHYJ_Date)}}</view>
				</view>
				<view class="line2"><view class="name">行政机关负责人审批意见：</view><view class="text indent">{{Entity.XZJGSHYJ_IsAgree}} </view></view>
				<view class="line3" v-if="Entity.XZJGSHYJ_IsAgree!=''">
					<view class="redbd" v-if="Item.SignName_XZJG==''"><view class="top">{{Item.XZJGRealName}}</view><view class="bottom">{{Item.XZJGLawNum}}</view></view>
					<view class="signname" v-else><image :src="Item.SignName_XZJG" mode="heightFix" /></view>
					<view class="text right">{{Tools.ToDateStr(Entity.XZJGSHYJ_Date)}}</view>
				</view>
			</view>
			<view class="square2" v-if="Item.State<3">
				<form @submit="formSubmit">
					<view :class="AuditNum==Audit.One && (Entity.AuditNum==Audit.One || Entity.AuditNum==Audit.Two)?'':'hidden'">
						<view class="cu-form-group border-b">
							<view class="title">审核意见</view>
							<view class="text">
								<picker :value="Tools.findStringIndex(ListCBRYJ,Entity.CBRYJ)" :range="ListCBRYJ" @change="CBRYJ_Change">
									<view class="uni-input">
										{{ListCBRYJ[Tools.findStringIndex(ListCBRYJ,Entity.CBRYJ)]}}<input name="CBRYJ" type="text" class="hidden" :value="ListCBRYJ[Tools.findStringIndex(ListCBRYJ,Entity.CBRYJ)]"/>
									</view>
								</picker>
							</view>
						</view>
						<view class="cu-form-group border-b" v-if="Entity.CBRYJ=='建议不予立案，理由：'">
							<view class="longtitle">填写理由</view>
							<view class="text">
								<textarea name="CBRYJ_Reason" placeholder="输入理由" :value="Entity.CBRYJ_Reason" @input="CBRYJ_Reason_Input"></textarea>
							</view>
						</view>
						<view class="cu-form-group border-b">
							<view class="title">选择日期</view>
							<view class="text">
								<picker name="CBRYJ_Date" mode="date" :value="Tools.ToDate(Entity.CBRYJ_Date,'请选择日期')" @change="CBRYJ_Date_Change">
									<view class="uni-input">{{Tools.ToDate(Entity.CBRYJ_Date,'请选择日期')}}</view>
								</picker>
							</view>
						</view>
						<view class="btn">
							<button class="assign" form-type="submit">确定</button>
						</view>
					</view>
					<view :class="AuditNum==Audit.Two && (Entity.AuditNum==Audit.Two || Entity.AuditNum==Audit.Four)?'':'hidden'">
						<view class="cu-form-group border-b">
							<view class="title">审核意见</view>
							<view class="text">
								<picker :value="Tools.findStringIndex(ListCBJGSHYJ,Entity.CBJGSHYJ_IsAgree)" :range="ListCBJGSHYJ" @change="CBJGSHYJ_IsAgree_Change">
									<view class="uni-input">
										{{ListCBJGSHYJ[Tools.findStringIndex(ListCBJGSHYJ,Entity.CBJGSHYJ_IsAgree)]}}<input name="CBJGSHYJ_IsAgree" type="text" class="hidden" :value="ListCBJGSHYJ[Tools.findStringIndex(ListCBJGSHYJ,Entity.CBJGSHYJ_IsAgree)]"/>
									</view>
								</picker>
							</view>
						</view>
						<view class="cu-form-group border-b">
							<view class="title">选择日期</view>
							<view class="text">
								<picker name="CBJGSHYJ_Date" mode="date" :value="Tools.ToDate(Entity.CBJGSHYJ_Date,'请选择日期')" @change="CBJGSHYJ_Date_Change">
									<view class="uni-input">{{Tools.ToDate(Entity.CBJGSHYJ_Date,'请选择日期')}}</view>
								</picker>
							</view>
						</view>
						<view class="btn">
							<button class="assign" form-type="submit">确定</button>
							<button class="cancel" @click="Cancel_CaseLaspb" v-if="Old.CBJGSHYJ_IsAgree!=''">回退</button>
						</view>
					</view>
					<view :class="AuditNum==Audit.Four && (Entity.AuditNum==Audit.Four || Entity.AuditNum==Audit.Zero)?'':'hidden'">
						<view class="cu-form-group border-b">
							<view class="title">审批意见</view>
							<view class="text">
								<picker :value="Tools.findStringIndex(ListXZJGSHYJ,Entity.XZJGSHYJ_IsAgree)" :range="ListXZJGSHYJ" @change="XZJGSHYJ_IsAgree_Change">
									<view class="uni-input">
										{{ListXZJGSHYJ[Tools.findStringIndex(ListXZJGSHYJ,Entity.XZJGSHYJ_IsAgree)]}}<input name="XZJGSHYJ_IsAgree" type="text" class="hidden" :value="ListXZJGSHYJ[Tools.findStringIndex(ListXZJGSHYJ,Entity.XZJGSHYJ_IsAgree)]"/>
									</view>
								</picker>
							</view>
						</view>
						<view class="cu-form-group border-b">
							<view class="title">选择日期</view>
							<view class="text">
								<picker name="XZJGSHYJ_Date" mode="date" :value="Tools.ToDate(Entity.XZJGSHYJ_Date,'请选择日期')" @change="XZJGSHYJ_Date_Change">
									<view class="uni-input">{{Tools.ToDate(Entity.XZJGSHYJ_Date,'请选择日期')}}</view>
								</picker>
							</view>
						</view>
						<view class="btn">
							<button class="assign" form-type="submit">确定</button>
							<button class="cancel" @click="Cancel_CaseLaspb" v-if="Old.XZJGSHYJ_IsAgree!=''">回退</button>
						</view>
					</view>
				</form>
			</view>
		</template>
		<view class="webview" v-if="TabIndex==2">
			<!-- #ifdef APP-->
			<web-view :update-title="false" :src="Domain+'/Admin/Case/'+Method+'.aspx?From=App&ID='+CaseID+'&Token='+Token+'&SubName='+SubName"></web-view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN || H5 -->
			<view class="preview" @click="Tools.Preview(CaseID,Method,SubName)">点此预览文书</view>
			<!-- #endif -->
		</view>
		<template v-if="TabIndex==3">
			<view class="square1 imglist5" v-if="(OldList.length+ImgList.length)>0">
				<view class="line1">
					<view class="img border" v-for="(img,index) in OldList"><image :src="Tools.GetImg(img,500)" mode="aspectFill" @click="Tools.PrevImg(OldList,index)"/><view class="delete" @click="DeleteImg1(index)" @click.stop="" v-if="Item.State==1"><image src="/static/error.png"/></view></view>
					<view class="img border" v-for="(img,index) in ImgList"><image :src="img" mode="aspectFill" @click="Tools.PrevImg(ImgList,index)"/><view class="delete" @click="DeleteImg2(index)" @click.stop="" v-if="Item.State==1"><image src="/static/error.png"/></view></view>
				</view>
			</view>
			<view class="imglist5" v-else>
				<view class="nodata"></view>
				<view class="loadmore">暂无图片</view>
			</view>
			<template v-if="Item.State==1">
				<view class="upimg" @click="ChooseImg()">点此选择所要上传的文书图片</view>
				<view class="btn"><button class="publishs" @click="Upload_Img()">确定</button></view>
			</template>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Old:{},
				CaseID:0,
				AnnexID:0,
				Audit:{},
				AuditNum:0,
				Item:{ID:0},
				Entity:{ID:0},
				SubName:'',
				Method:'',
				Expand:{},
				Token:'',
				Domain:'',
				TabIndex:1,
				OldList:[],
				ImgList:[],
				ListCBRYJ:['选择审核意见'],
				ListCBJGSHYJ:['选择审核意见'],
				ListXZJGSHYJ:['选择审批意见']
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({title:options.SubName});
			this.SubName=options.SubName;
			this.CaseID=options.CaseID;
			this.Method=options.Method;
			this.Audit=this.Util.Audit;
			this.Domain = this.Util.Domain;
			this.Token=uni.getStorageSync("Token");
			this.AuditNum=uni.getStorageSync("AuditNum");
			this.ListCBRYJ.push("建议立案");
			this.ListCBRYJ.push("建议不予立案，理由：");
			this.ListCBJGSHYJ.push("拟同意");
			this.ListCBJGSHYJ.push("拟不同意");
			this.ListXZJGSHYJ.push("同意");
			this.ListXZJGSHYJ.push("不同意");
			this.Find_CaseInfo();
		},
		methods:{
			//承办人
			CBRYJ_Change(e){
				this.Entity.CBRYJ=this.ListCBRYJ[e.detail.value];
			},
			CBRYJ_Date_Change(e){
				this.Entity.CBRYJ_Date=e.detail.value;
			},
			CBRYJ_Reason_Input(e){
				this.Entity.CBRYJ_Reason = e.detail.value;
			},
			//承办机构
			CBJGSHYJ_IsAgree_Change(e){
				this.Entity.CBJGSHYJ_IsAgree=this.ListCBJGSHYJ[e.detail.value];
			},
			CBJGSHYJ_Date_Change(e){
				this.Entity.CBJGSHYJ_Date=e.detail.value;
			},
			//行政机关负责人
			XZJGSHYJ_IsAgree_Change(e){
				this.Entity.XZJGSHYJ_IsAgree=this.ListXZJGSHYJ[e.detail.value];
			},
			XZJGSHYJ_Date_Change(e){
				this.Entity.XZJGSHYJ_Date=e.detail.value;
			},
			LayTab(TabIndex){
				this.TabIndex=TabIndex;
				// #ifdef APP-PLUS
				if(this.TabIndex==2){
					this.Util.Loading("加载中,请稍候...");
					var currentWebview = this.$scope.$getAppWebview(); //获取当前页面的webview对象
					setTimeout(()=> {
						var wv = currentWebview.children()[0] //取出当前webview实例
						wv.setStyle({
							scalable: true  //添加样式，启动缩放
						});
					}, 1000);
					setTimeout(()=> {
						this.Util.HideLoading();
					},1000);
				}
				// #endif
			},
			Find_CaseInfo(){
				var data = {};
				data.Act="Find_CaseInfo";
				data.CaseID=this.CaseID;
				data.Method=this.Method;
				this.Util.Loading("加载中...");
				this.Util.Post(data, json=>{
					this.Util.HideLoading();
					uni.stopPullDownRefresh();
					uni.hideNavigationBarLoading();
					this.Old = {...json.Data.Entity};
					this.Item = json.Data.Info;
					this.Entity = json.Data.Entity;
					this.Expand = json.Data.Expand;
					this.OldList = json.Data.ImgList;
					this.AnnexID = json.Data.AnnexID;
				});
			},
			formSubmit(e){
				this.Util.Confirm("是否确定？",res=>{
					var data = e.detail.value;
					data.Act="Save_CaseLaspb";
					data.CaseID=this.CaseID;
					this.Util.Loading("请稍候...");
					this.Util.Post(data, json=>{
						this.Util.HideLoading();
						if(json.State){
							this.Util.Toast(json.Msg, obj=>{
								uni.$emit("Success");
								uni.navigateBack({delta:2});
							});
						}else{
							this.Util.Alert(json.Msg);
						}
					});
				});
			},
			Cancel_CaseLaspb(){
				this.Util.Confirm("您确定要回退（取消审核）吗？",res=>{
					var data={};
					data.Act="Cancel_CaseLaspb";
					data.ID = this.Entity.ID;
					data.CaseID=this.CaseID;
					this.Util.Loading("请稍候...");
					this.Util.PostAdmin(data, json=>{
						this.Util.HideLoading();
						if(json.State){
							this.Util.Toast(json.Msg, obj=>{
								uni.$emit("Success");
								uni.navigateBack({delta:2});
							});
						}else{
							this.Util.Alert(json.Msg);
						}
					});
				});
			},
			Upload_Img(){
				var data = {};
				data.Act="Upload_Img";
				data.ID=this.AnnexID;
				data.Type=1;
				data.CaseID=this.CaseID;
				data.Method=this.Method;		
				this.Util.Loading("请稍候...");
				if(this.ImgList.length>0){
					var ImgList=this.Util.TranList(this.ImgList).reverse();
					this.Util.Upload(ImgList,"upload_file_o",[],list=>{
						data.Imgs = this.OldList.concat(list).join(",");
						this.Save(data);
					});
				}else{
					data.Imgs = this.OldList.join(",");
					this.Save(data);
				}
			},
			Save(data){
				this.Util.PostAdmin(data, json=>{
					this.Util.HideLoading();
					if(json.State){
						this.Util.Toast(json.Msg);
					}else{
						this.Util.Alert(json.Msg);
					}
				});
			},
			ChooseImg() {
				uni.chooseImage({
					count: 9, // 默认9
					sizeType: ['original'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: res=> {
						var ImgList=[];
						res.tempFilePaths.forEach(item=>{
							ImgList.push(item);
						});						
						this.ImgList = this.ImgList.concat(ImgList);
					}
				});
			},
			DeleteImg1(index){
				const self = this
				this.Util.Confirm("您确定要删除吗？",item=>{
					self.OldList.splice(index,1)
				});
			},
			DeleteImg2(index){
				const self = this
				this.Util.Confirm("您确定要删除吗？",item=>{
					self.ImgList.splice(index,1)
				});
			}
		}
	}
</script>

<style lang="scss">
	
</style>
